package com.lenovo.lcdm.type.util;

import com.lenovo.lcdm.type.dto.TypeDefinitionDTO;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.function.Consumer;

/**
 * @author
 */
public class TypeDefinitionDTOWalker {


    public static void preOrderWalk(List<TypeDefinitionDTO> types, Consumer<TypeDefinitionDTO> consumer) {
        if (CollectionUtils.isEmpty(types)) {
            return;
        }

        types.forEach(type -> {
            consumer.accept(type);
            preOrderWalk(type.getSubTypes(), consumer);
        });
    }
}
